//
//  AddBankCartViewController.m
//  PropertyManager
//
//  Created by TNG on 2018/7/18.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "AddBankCartViewController.h"

@interface AddBankCartViewController () <UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UITableView * tableview;

@end

@implementation AddBankCartViewController

static NSString * cellID = @"cell";
static NSString * PropertyReparisInputInfoTableViewCellID = @"PropertyReparisInputInfoTableViewCell";
static NSString * PropertyReairsCommitTableViewCellID = @"PropertyReairsCommitTableViewCell";
static NSString * BandCardCodeTableViewCellID = @"BandCardCodeTableViewCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"新增银行卡";
    [self creatTableview];
    [self registCell];
}

-(void)registCell
{
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    [self.tableview registerClass:[PropertyReparisInputInfoTableViewCell class] forCellReuseIdentifier:PropertyReparisInputInfoTableViewCellID];
    [self.tableview registerClass:[PropertyReairsCommitTableViewCell class] forCellReuseIdentifier:PropertyReairsCommitTableViewCellID];
    [self.tableview registerClass:[BandCardCodeTableViewCell class] forCellReuseIdentifier:BandCardCodeTableViewCellID];
}

-(void)creatTableview{
    if (self.tableview == nil) {
        UITableView * tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, kStatusAndNavBarH, WIDTH, HEIGHT - kStatusAndNavBarH - kHomeLineH) style:UITableViewStylePlain];
        tableview.delegate = self;
        tableview.dataSource = self;
        tableview.backgroundColor = SFMWhiteColor;
        if (@available(iOS 11.0, *)) {
            tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
        }
        self.tableview = tableview;
        [self.view addSubview:self.tableview];
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 40)];
    line.backgroundColor = SFM242;
    
    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, WIDTH - 40, 40)];
    titleLabel.font = font(12);
    titleLabel.textColor = SFM153;
    titleLabel.textAlignment = NSTextAlignmentLeft;
    if (section == 0) {
        titleLabel.text = @"确认银行卡信息";
    }else
    {
        titleLabel.text = @"身份验证";
    }
    [line addSubview:titleLabel];
    return line;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        if (indexPath.row == 2) {
            return 130;
        }
    }
    return 55;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        PropertyReparisInputInfoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:PropertyReparisInputInfoTableViewCellID];
        if (indexPath.row == 0) {
            cell.titleLabel.text = @"持卡人";
            cell.textfiled.placeholder = @"请输入持卡人";
        }else if(indexPath.row == 1)
        {
            cell.titleLabel.text = @"卡号";
            cell.textfiled.placeholder = @"请输入卡号";
            cell.textfiled.keyboardType = UIKeyboardTypeNumberPad;
        }else
        {
            cell.titleLabel.text = @"身份证号码";
            cell.textfiled.placeholder = @"请输入身份证号码";
            cell.textfiled.keyboardType = UIKeyboardTypeNumberPad;
        }
        return cell;
    }else
    {
        if (indexPath.row == 0) {
            PropertyReparisInputInfoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:PropertyReparisInputInfoTableViewCellID];
            cell.titleLabel.text = @"银行预留手机号";
            cell.textfiled.placeholder = @"请输入银行预留手机号";
            cell.textfiled.keyboardType = UIKeyboardTypeNumberPad;
            return cell;
        }else if (indexPath.row == 1)
        {
            BandCardCodeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:BandCardCodeTableViewCellID];
            return cell;
        }else
        {
            PropertyReairsCommitTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:PropertyReairsCommitTableViewCellID];
            [cell.btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [cell.btn setTitle:@"确认绑卡" forState:UIControlStateNormal];
            return cell;
        }
    }
}

#pragma mark - 确认绑卡
-(void)btnClick:(UIButton *)btn
{
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
